package com.agv.web.util;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class UUIDGen {

	public static String genUUID() {
		try {
			int random = java.util.UUID.randomUUID().toString().hashCode();
			if (random < 0) {
				random *= -1;
			}

			String randomStr = String.valueOf(random);
			if (randomStr.length() >= 4) {
				randomStr = randomStr.substring(0, 4);
			} else {
				while (randomStr.length() != 4) {
					randomStr += "X";
				}
			}

			Calendar calendar = new GregorianCalendar();

			String day = String.valueOf(calendar.get(Calendar.DATE)).length() == 1 ? "0"
					+ calendar.get(Calendar.DATE)
					: String.valueOf(calendar.get(Calendar.DATE));

			String month = String.valueOf(calendar.get(Calendar.MONTH) + 1)
					.length() == 1 ? "0" + (calendar.get(Calendar.MONTH) + 1)
					: String.valueOf(calendar.get(Calendar.MONTH) + 1);

			String UUID = day + month + "-" + randomStr;
			return UUID;
		} catch (Exception e) {
			return "0000-0000";
		}
	}

}
